const webpack = require('webpack')

console.log(process.argv)
var fs = require("fs")
var useFakeUrl = true
var url = ""
try{
    var arr = process.argv[2]
    if(arr === 'serve'){
        useFakeUrl = false
        url = "http://106.52.185.146"
    }
    try{
        //tecent
        if(process.argv[3] === '--tencent'){
            useFakeUrl = false
            url = "http://106.52.185.146"
        }
    } catch (e) {
    }
} catch (e) {
}
var urls = require("./src/url/real.js")
if(useFakeUrl){
    var mp = {}
    for(var k in urls){
        mp[k] = `${url}/proxy/bpm/${k}`
    }
    fs.writeFileSync("./src/url/url.js", `export default ${JSON.stringify(mp)}`)
} else {
    for(var k in urls){
        urls[k] = `${url}${urls[k]}`
    }
    fs.writeFileSync("./src/url/url.js", `export default ${JSON.stringify(urls)}`)
}


const FileManagerPlugin = require('filemanager-webpack-plugin')

module.exports = {
    publicPath: "./",
    configureWebpack: {
        plugins: [
            new webpack.ProvidePlugin({
                $:"jquery",
                jQuery:"jquery",
                "windows.jQuery":"jquery"
            }),
            new FileManagerPlugin({
                events:{
                    onEnd: {
                        delete: [
                            './dist/dist.zip',
                        ],
                        archive: [
                            {source: './dist', destination: './dist/dist.zip'},
                        ]
                    }
                }
            })
        ]
    },
    // devServer: {
    //     proxy: {
    //         '/bpm': {
    //             target: 'http://47.94.97.138:8091',//目标地址
    //             ws: true, //// 是否启用websockets
    //             changeOrigin: true, //开启代理：在本地会创建一个虚拟服务端，然后发送请求的数据，并同时接收请求的数据，这样服务端和服务端进行数据的交互就不会有跨域问题
    //             pathRewrite: {'^/bpm': '/api/bpm'}    //这里重写路径
    //         }
    //
    //     }
    // },
}
